/*
 * CSVPanel.java
 *
 * --- Last Update: 6/22/2010 4:58 PM ---
 *
 * Update Notes 6/22/2010 4:58 PM by Adrian Wijasa:
 * Changed the Help Texts so that they don't mention Banner when they really mean the Database, which could be
 * Oracle, MySQL, or PostgreSQL.
 *
 * Update Notes 6/19/2010 6:32 PM by Adrian Wijasa:
 * Removed all uses of main.checkConnection methods. Before, the checkConnection method is used to let the
 * user enters his/her credentials whenever any info needs to be obtained from Database. Now, users have to
 * provide their credentials before CSVPanel is opened.
 *
 * Update Notes 6/1/2010 1:20 PM by Adrian Wijasa:
 * Edited the Help Text of Column Text Field.
 *
 * Update Notes 5/18/2010 1:32 AM by Adrian Wijasa:
 * Removed the handling of Schema and Table text fields so that CSV Loader can work easily with case sensitive
 * databases.  Instead of typing in the Schema and Table information, user now must select the DB Columns where
 * the CSV Column should go to.  By selecting instead of typing, the input will always have the correct upper
 * case/lower case letters.
 *
 * Update Notes 5/13/2010 11:45 PM by Adrian Wijasa:
 * Displays Help when a mouse click event happened on:
 * Schema Text Field
 * Table Text Field
 * Column Text Field.
 *
 * Update Notes 5/3/2010 2:03 AM by Adrian Wijasa:
 * Added initButtons method to reduce some button sizes whenever this program is run under Linux.  This is to
 * prevent the button texts from being clipped.
 *
 * Displays Help when the mouse pointer hovers on:
 * CSV Data Snapshot
 * Add New Column
 * Save Configuration to File
 * Create CSV
 * Create SQL Insert
 * Create SQL Merge.
 *
 * Update Notes 4/29/2010 11:36 PM by Adrian Wijasa:
 * Displays Help when the mouse pointer hovers on:
 * Produce a Data Type & Length Report
 * Report Plan.
 *
 * Update Notes 4/18/2010 3:07 PM by Adrian Wijasa:
 * This class is made to work with Java 5.
 *
 * Update Notes 4/6/2010 10:02 PM by Adrian Wijasa:
 * Added the Schema Text Field Input.
 *
 * Removed the ability to create a backup CSVPanelImage and revert to it.  This feature is redundant to 'Save
 * Configuration to File'.
 *
 * Removed 'Delete Column' button, because it is redundant to 'Do not Load this Column' checkbox.
 *
 * Added a Schema Text Field, so that a user can specify the schema where a column should go to without having
 * to configure the sqlList ('Load this Column into' box).
 *
 * Update Notes 3/22/2010 4:28 PM by Adrian Wijasa:
 * Re-adjusted the form design so that it will look good under Java Metal UI.
 *
 * Update Notes 1/30/2010 11:31 PM by Adrian Wijasa:
 * Added "Create SQL Merge" button.
 *
 * Update Notes 1/30/2010 12:24 PM by Adrian Wijasa:
 * Renamed "Report Insertion Plan" button to "Report Plan"
 *
 * Created on March 5, 2007, 10:59 AM
 *
 * CSV Loader
 * Copyright 2007, 2009, 2010 Adrian Wijasa
 *
 * This file is part of CSV Loader.
 *
 * CSV Loader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CSV Loader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CSV Loader.  If not, see <http://www.gnu.org/licenses/>.
 */

package panels;

import csv.CSVPanelImage;
import forms.AddNewColFrame;
import forms.FileChooserFrame;
import forms.Main;
import java.awt.event.KeyEvent;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.ListSelectionModel;
import table.StaticTableModel;

/**
 * Panel to customize a selected CSV file, so it can be converted to an
 * effective SQL Insert/Update file
 * 
 * @author matianyuan
 */
public class CSVPanel extends javax.swing.JPanel {

    /** Creates new form CSVPanel */
    public CSVPanel( Main main ) {
        this.main = main;
        listArrayList = new ArrayList<String>();
        initComponents();
        initButtons();
        initTable();
        initHelp();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        csvScrollPane = new javax.swing.JScrollPane();
        csvTable = new javax.swing.JTable();
        columnPanel = new javax.swing.JPanel();
        columnLabel = new javax.swing.JLabel();
        dataTypeLabel = new javax.swing.JLabel();
        nullLabel = new javax.swing.JLabel();
        includeCheckBox = new javax.swing.JCheckBox();
        colonLabel3 = new javax.swing.JLabel();
        colonLabel4 = new javax.swing.JLabel();
        colonLabel5 = new javax.swing.JLabel();
        columnTextField = new javax.swing.JTextField();
        sqlPanel = new javax.swing.JPanel();
        sqlScrollPane = new javax.swing.JScrollPane();
        sqlList = new javax.swing.JList();
        addSqlLabel = new javax.swing.JLabel();
        removeSqlLabel = new javax.swing.JLabel();
        dataTypeTextField = new javax.swing.JTextField();
        nullTextField = new javax.swing.JTextField();
        addLabel = new javax.swing.JLabel();
        helpPanel = new javax.swing.JPanel();
        helpScrollPane = new javax.swing.JScrollPane();
        helpTextPane = new javax.swing.JTextPane();
        closeLabel = new javax.swing.JLabel();
        actionPanel = new javax.swing.JPanel();
        metaDataLabel = new javax.swing.JLabel();
        planLabel = new javax.swing.JLabel();
        saveConfigLabel = new javax.swing.JLabel();
        createCSVLabel = new javax.swing.JLabel();
        sqlActionPanel = new javax.swing.JPanel();
        createSQLInsertLabel = new javax.swing.JLabel();
        createSQLMergeLabel = new javax.swing.JLabel();

        csvScrollPane.setPreferredSize(new java.awt.Dimension(760, 140));

        csvTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        csvTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        csvTable.setColumnSelectionAllowed(true);
        csvTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                csvTableMouseReleased(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                csvTableMouseEntered(evt);
            }
        });
        csvTable.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                csvTableKeyReleased(evt);
            }
        });
        csvScrollPane.setViewportView(csvTable);

        columnPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Column Config", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 11))); // NOI18N

        columnLabel.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        columnLabel.setText("Column");
        columnLabel.setPreferredSize(new java.awt.Dimension(90, 14));

        dataTypeLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        dataTypeLabel.setText("Data Type");
        dataTypeLabel.setPreferredSize(new java.awt.Dimension(90, 14));

        nullLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        nullLabel.setText("Null / Not Null");
        nullLabel.setPreferredSize(new java.awt.Dimension(90, 14));

        includeCheckBox.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        includeCheckBox.setForeground(new java.awt.Color(255, 0, 0));
        includeCheckBox.setText("Do not Load this Column");
        includeCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        includeCheckBox.setEnabled(false);
        includeCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        includeCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                includeCheckBoxActionPerformed(evt);
            }
        });

        colonLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        colonLabel3.setText(": ");

        colonLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
        colonLabel4.setText(": ");

        colonLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
        colonLabel5.setText(": ");

        columnTextField.setEnabled(false);
        columnTextField.setPreferredSize(new java.awt.Dimension(300, 20));
        columnTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                columnTextFieldMouseClicked(evt);
            }
        });
        columnTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                columnTextFieldActionPerformed(evt);
            }
        });
        columnTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                columnTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                columnTextFieldFocusLost(evt);
            }
        });

        sqlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Load this Column into:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 11))); // NOI18N

        sqlList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                sqlListMouseEntered(evt);
            }
        });
        sqlScrollPane.setViewportView(sqlList);

        addSqlLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        addSqlLabel.setForeground(new java.awt.Color(0, 102, 255));
        addSqlLabel.setText("Add");
        addSqlLabel.setEnabled(false);
        addSqlLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addSqlLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                addSqlLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                addSqlLabelMouseExited(evt);
            }
        });

        removeSqlLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        removeSqlLabel.setForeground(new java.awt.Color(0, 102, 255));
        removeSqlLabel.setText("Remove");
        removeSqlLabel.setEnabled(false);
        removeSqlLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeSqlLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                removeSqlLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                removeSqlLabelMouseExited(evt);
            }
        });

        org.jdesktop.layout.GroupLayout sqlPanelLayout = new org.jdesktop.layout.GroupLayout(sqlPanel);
        sqlPanel.setLayout(sqlPanelLayout);
        sqlPanelLayout.setHorizontalGroup(
            sqlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sqlPanelLayout.createSequentialGroup()
                .add(sqlScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 303, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sqlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(removeSqlLabel)
                    .add(addSqlLabel))
                .addContainerGap())
        );
        sqlPanelLayout.setVerticalGroup(
            sqlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sqlPanelLayout.createSequentialGroup()
                .add(22, 22, 22)
                .add(addSqlLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(removeSqlLabel)
                .addContainerGap(116, Short.MAX_VALUE))
            .add(sqlScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
        );

        dataTypeTextField.setEditable(false);

        nullTextField.setEditable(false);

        org.jdesktop.layout.GroupLayout columnPanelLayout = new org.jdesktop.layout.GroupLayout(columnPanel);
        columnPanel.setLayout(columnPanelLayout);
        columnPanelLayout.setHorizontalGroup(
            columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(columnPanelLayout.createSequentialGroup()
                .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(columnPanelLayout.createSequentialGroup()
                        .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, columnPanelLayout.createSequentialGroup()
                                .add(nullLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(colonLabel5))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, columnPanelLayout.createSequentialGroup()
                                .add(dataTypeLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(colonLabel4)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(dataTypeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                            .add(nullTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)))
                    .add(columnPanelLayout.createSequentialGroup()
                        .add(columnLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(colonLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(columnTextField, 0, 0, Short.MAX_VALUE))
                    .add(includeCheckBox)
                    .add(sqlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 376, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        columnPanelLayout.setVerticalGroup(
            columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(columnPanelLayout.createSequentialGroup()
                .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(columnLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(colonLabel3)
                    .add(columnTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(dataTypeLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(colonLabel4)
                    .add(dataTypeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(columnPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nullLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(colonLabel5)
                    .add(nullTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(includeCheckBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sqlPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        addLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        addLabel.setForeground(new java.awt.Color(0, 102, 255));
        addLabel.setText("Add New Column");
        addLabel.setEnabled(false);
        addLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                addLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                addLabelMouseExited(evt);
            }
        });

        helpPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Help", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 11))); // NOI18N

        helpScrollPane.setBorder(null);

        helpTextPane.setBackground(new java.awt.Color(236, 233, 216));
        helpTextPane.setBorder(null);
        helpTextPane.setEditable(false);
        helpScrollPane.setViewportView(helpTextPane);

        org.jdesktop.layout.GroupLayout helpPanelLayout = new org.jdesktop.layout.GroupLayout(helpPanel);
        helpPanel.setLayout(helpPanelLayout);
        helpPanelLayout.setHorizontalGroup(
            helpPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(helpPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(helpScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                .addContainerGap())
        );
        helpPanelLayout.setVerticalGroup(
            helpPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(helpPanelLayout.createSequentialGroup()
                .add(helpScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                .addContainerGap())
        );

        closeLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        closeLabel.setForeground(new java.awt.Color(0, 102, 255));
        closeLabel.setText("Close");
        closeLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                closeLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                closeLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                closeLabelMouseExited(evt);
            }
        });

        metaDataLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        metaDataLabel.setForeground(new java.awt.Color(0, 102, 255));
        metaDataLabel.setText("Produce a Data Type & Length Report");
        metaDataLabel.setEnabled(false);
        metaDataLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                metaDataLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                metaDataLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                metaDataLabelMouseExited(evt);
            }
        });

        planLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        planLabel.setForeground(new java.awt.Color(0, 102, 255));
        planLabel.setText("Report Plan");
        planLabel.setEnabled(false);
        planLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                planLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                planLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                planLabelMouseExited(evt);
            }
        });

        saveConfigLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        saveConfigLabel.setForeground(new java.awt.Color(0, 102, 255));
        saveConfigLabel.setText("Save Configuration to File");
        saveConfigLabel.setEnabled(false);
        saveConfigLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveConfigLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                saveConfigLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                saveConfigLabelMouseExited(evt);
            }
        });

        createCSVLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        createCSVLabel.setForeground(new java.awt.Color(0, 102, 255));
        createCSVLabel.setText("Create CSV");
        createCSVLabel.setEnabled(false);
        createCSVLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                createCSVLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                createCSVLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                createCSVLabelMouseExited(evt);
            }
        });

        createSQLInsertLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        createSQLInsertLabel.setForeground(new java.awt.Color(0, 102, 255));
        createSQLInsertLabel.setText("Create SQL Insert");
        createSQLInsertLabel.setEnabled(false);
        createSQLInsertLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                createSQLInsertLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                createSQLInsertLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                createSQLInsertLabelMouseExited(evt);
            }
        });

        createSQLMergeLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        createSQLMergeLabel.setForeground(new java.awt.Color(0, 102, 255));
        createSQLMergeLabel.setText("Create SQL Merge");
        createSQLMergeLabel.setEnabled(false);
        createSQLMergeLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                createSQLMergeLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                createSQLMergeLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                createSQLMergeLabelMouseExited(evt);
            }
        });

        org.jdesktop.layout.GroupLayout sqlActionPanelLayout = new org.jdesktop.layout.GroupLayout(sqlActionPanel);
        sqlActionPanel.setLayout(sqlActionPanelLayout);
        sqlActionPanelLayout.setHorizontalGroup(
            sqlActionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sqlActionPanelLayout.createSequentialGroup()
                .add(sqlActionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(createSQLInsertLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                    .add(createSQLMergeLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(14, 14, 14))
        );
        sqlActionPanelLayout.setVerticalGroup(
            sqlActionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sqlActionPanelLayout.createSequentialGroup()
                .add(createSQLInsertLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(createSQLMergeLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        org.jdesktop.layout.GroupLayout actionPanelLayout = new org.jdesktop.layout.GroupLayout(actionPanel);
        actionPanel.setLayout(actionPanelLayout);
        actionPanelLayout.setHorizontalGroup(
            actionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(actionPanelLayout.createSequentialGroup()
                .add(metaDataLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(48, 48, 48)
                .add(planLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(37, 37, 37)
                .add(saveConfigLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(44, 44, 44)
                .add(createCSVLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                .add(27, 27, 27)
                .add(sqlActionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        actionPanelLayout.setVerticalGroup(
            actionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(actionPanelLayout.createSequentialGroup()
                .add(actionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(actionPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(saveConfigLabel)
                        .add(createCSVLabel)
                        .add(metaDataLabel)
                        .add(planLabel))
                    .add(sqlActionPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, actionPanel, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(columnPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 386, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(addLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(helpPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, csvScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)
                    .add(closeLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(closeLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(csvScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(addLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(helpPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(columnPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(actionPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void csvTableMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_csvTableMouseEntered
        csvTable.requestFocus();
        helpTextPane.setText( csvSnapshotHelp );
}//GEN-LAST:event_csvTableMouseEntered

    private void csvTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_csvTableMouseReleased
        selectedColIndex = csvTable.getSelectedColumn();
        selectedRowIndex = csvTable.getSelectedRow();
        loadCol( selectedColIndex );
}//GEN-LAST:event_csvTableMouseReleased

    private void csvTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_csvTableKeyReleased
        if( evt.getKeyCode() == KeyEvent.VK_LEFT ||
                evt.getKeyCode() == KeyEvent.VK_RIGHT ||
                evt.getKeyCode() == KeyEvent.VK_HOME ||
                evt.getKeyCode() == KeyEvent.VK_END ||
                evt.getKeyCode() == KeyEvent.VK_TAB ) {
            selectedColIndex = csvTable.getSelectedColumn();
            selectedRowIndex = csvTable.getSelectedRow();
            loadCol( selectedColIndex );
        }
}//GEN-LAST:event_csvTableKeyReleased

    private void includeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_includeCheckBoxActionPerformed
        updateCurrentImage( INCLUDE );
}//GEN-LAST:event_includeCheckBoxActionPerformed

    private void columnTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_columnTextFieldActionPerformed
        updateCurrentImage( COLUMN );
}//GEN-LAST:event_columnTextFieldActionPerformed

    private void columnTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_columnTextFieldFocusGained
        helpTextPane.setText( columnHelp );
}//GEN-LAST:event_columnTextFieldFocusGained

    private void columnTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_columnTextFieldFocusLost
        updateCurrentImage( COLUMN );
}//GEN-LAST:event_columnTextFieldFocusLost

    private void addSqlLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addSqlLabelMouseClicked
        if( addSqlLabel.isEnabled() ) {
            addSqlLabel.setForeground( main.red );

            main.popUpDBColSelector();
        }
}//GEN-LAST:event_addSqlLabelMouseClicked

    private void addSqlLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addSqlLabelMouseEntered
        addSqlLabel.setForeground( main.black );
        helpTextPane.setText( sqlListHelp );
}//GEN-LAST:event_addSqlLabelMouseEntered

    private void addSqlLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addSqlLabelMouseExited
        addSqlLabel.setForeground( main.blue );
}//GEN-LAST:event_addSqlLabelMouseExited

    private void removeSqlLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeSqlLabelMouseClicked
        if( removeSqlLabel.isEnabled() ) {
            removeSqlLabel.setForeground( main.red );

            Object toRemoveVals[] = sqlList.getSelectedValues();

            if( toRemoveVals != null ) {
                for( int i = 0; i < toRemoveVals.length; i++ ) {
                    listArrayList.remove( "" + toRemoveVals[i] );
                }

                sqlList.setListData( listArrayList.toArray() );
                updateCurrentImage( SQL );
            }
        }
}//GEN-LAST:event_removeSqlLabelMouseClicked

    private void removeSqlLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeSqlLabelMouseEntered
        removeSqlLabel.setForeground( main.black );
        helpTextPane.setText( sqlListHelp );
}//GEN-LAST:event_removeSqlLabelMouseEntered

    private void removeSqlLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeSqlLabelMouseExited
        removeSqlLabel.setForeground( main.blue );
}//GEN-LAST:event_removeSqlLabelMouseExited

    private void addLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addLabelMouseClicked
        if( addLabel.isEnabled() ) {
            addLabel.setForeground( main.red );
            main.setEnabled( false );
            new AddNewColFrame( main ).setVisible( true );
        }
}//GEN-LAST:event_addLabelMouseClicked

    private void addLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addLabelMouseExited
        addLabel.setForeground( main.blue );
}//GEN-LAST:event_addLabelMouseExited

    private void addLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addLabelMouseEntered
        addLabel.setForeground( main.black );
        helpTextPane.setText( addNewColHelp );
}//GEN-LAST:event_addLabelMouseEntered

    private void closeLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeLabelMouseClicked
        closeLabel.setForeground( main.red );

        main.csvMenu.setEnabled( false );
        main.csvMenuItem.setEnabled( true );
        main.welcomePanel.csvLabel.setEnabled( true );
        main.tabbedPane.remove( this );
}//GEN-LAST:event_closeLabelMouseClicked

    private void closeLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeLabelMouseExited
        closeLabel.setForeground( main.blue );
}//GEN-LAST:event_closeLabelMouseExited

    private void closeLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeLabelMouseEntered
        closeLabel.setForeground( main.black );
}//GEN-LAST:event_closeLabelMouseEntered

    private void metaDataLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_metaDataLabelMouseClicked
        if( metaDataLabel.isEnabled() ) {
            metaDataLabel.setForeground( main.red );

            main.popUpFileChooser( FileChooserFrame.SAVE_METADATA );
        }
}//GEN-LAST:event_metaDataLabelMouseClicked

    private void metaDataLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_metaDataLabelMouseEntered
        metaDataLabel.setForeground( main.black );
        helpTextPane.setText( dataTypeLengthHelp );
}//GEN-LAST:event_metaDataLabelMouseEntered

    private void metaDataLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_metaDataLabelMouseExited
        metaDataLabel.setForeground( main.blue );
}//GEN-LAST:event_metaDataLabelMouseExited

    private void planLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_planLabelMouseClicked
        if( planLabel.isEnabled() ) {
            planLabel.setForeground( main.red );

            main.popUpPlanWindow();
        }
}//GEN-LAST:event_planLabelMouseClicked

    private void planLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_planLabelMouseEntered
        planLabel.setForeground( main.black );
        helpTextPane.setText( planHelp );
}//GEN-LAST:event_planLabelMouseEntered

    private void planLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_planLabelMouseExited
        planLabel.setForeground( main.blue );
}//GEN-LAST:event_planLabelMouseExited

    private void saveConfigLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveConfigLabelMouseClicked
        if( saveConfigLabel.isEnabled() ) {
            saveConfigLabel.setForeground( main.red );
            main.popUpFileChooser( FileChooserFrame.SAVE_IMAGE );
        }
}//GEN-LAST:event_saveConfigLabelMouseClicked

    private void saveConfigLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveConfigLabelMouseEntered
        saveConfigLabel.setForeground( main.black );
        helpTextPane.setText( saveConfigHelp );
}//GEN-LAST:event_saveConfigLabelMouseEntered

    private void saveConfigLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveConfigLabelMouseExited
        saveConfigLabel.setForeground( main.blue );
}//GEN-LAST:event_saveConfigLabelMouseExited

    private void createCSVLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createCSVLabelMouseClicked
        if( createCSVLabel.isEnabled() ) {
            createCSVLabel.setForeground( main.red );
            main.popUpFileChooser( FileChooserFrame.SAVE_CSV );
        }
}//GEN-LAST:event_createCSVLabelMouseClicked

    private void createCSVLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createCSVLabelMouseEntered
        createCSVLabel.setForeground( main.black );
        helpTextPane.setText( createCSVHelp );
}//GEN-LAST:event_createCSVLabelMouseEntered

    private void createCSVLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createCSVLabelMouseExited
        createCSVLabel.setForeground( main.blue );
}//GEN-LAST:event_createCSVLabelMouseExited

    private void createSQLInsertLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLInsertLabelMouseClicked
        if( createSQLInsertLabel.isEnabled() ) {
            createSQLInsertLabel.setForeground( main.red );

            main.popUpFileChooser( FileChooserFrame.SAVE_SQL_INSERT );
        }
}//GEN-LAST:event_createSQLInsertLabelMouseClicked

    private void createSQLInsertLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLInsertLabelMouseEntered
        createSQLInsertLabel.setForeground( main.black );
        helpTextPane.setText( createInsertHelp );
}//GEN-LAST:event_createSQLInsertLabelMouseEntered

    private void createSQLInsertLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLInsertLabelMouseExited
        createSQLInsertLabel.setForeground( main.blue );
}//GEN-LAST:event_createSQLInsertLabelMouseExited

    private void createSQLMergeLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLMergeLabelMouseClicked
        if( createSQLMergeLabel.isEnabled() ) {
            createSQLMergeLabel.setForeground( main.red );

            main.popUpFileChooser( FileChooserFrame.SAVE_SQL_MERGE );
        }
}//GEN-LAST:event_createSQLMergeLabelMouseClicked

    private void createSQLMergeLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLMergeLabelMouseEntered
        createSQLMergeLabel.setForeground( main.black );
        helpTextPane.setText( createMergeHelp );
}//GEN-LAST:event_createSQLMergeLabelMouseEntered

    private void createSQLMergeLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createSQLMergeLabelMouseExited
        createSQLMergeLabel.setForeground( main.blue );
}//GEN-LAST:event_createSQLMergeLabelMouseExited

    private void sqlListMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sqlListMouseEntered
        helpTextPane.setText( sqlListHelp );
    }//GEN-LAST:event_sqlListMouseEntered

    private void columnTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_columnTextFieldMouseClicked
        helpTextPane.setText( columnHelp );
    }//GEN-LAST:event_columnTextFieldMouseClicked

    private void disablePanel() {
        addLabel.setEnabled( false );
        columnTextField.setEnabled( false );
        columnTextField.setText( "" );
        dataTypeTextField.setText( "" );
        nullTextField.setText( "" );
        includeCheckBox.setEnabled( false );
        includeCheckBox.setSelected( false );
        addSqlLabel.setEnabled( false );
        removeSqlLabel.setEnabled( false );
        sqlList.setListData( new ArrayList<String>().toArray() );
        createCSVLabel.setEnabled( false );
        createSQLInsertLabel.setEnabled( false );
        createSQLMergeLabel.setEnabled( false );
        saveConfigLabel.setEnabled( false );
        main.cfgUploadMenuItem.setEnabled( false );
        planLabel.setEnabled( false );
        metaDataLabel.setEnabled( false );
    }

    private void enablePanel() {
        addLabel.setEnabled( true );
        columnTextField.setEnabled( true );
        includeCheckBox.setEnabled( true );
        addSqlLabel.setEnabled( true );
        removeSqlLabel.setEnabled( true );
        createCSVLabel.setEnabled( true );
        createSQLInsertLabel.setEnabled( true );
        createSQLMergeLabel.setEnabled( true );
        saveConfigLabel.setEnabled( true );
        main.cfgUploadMenuItem.setEnabled( true );
        planLabel.setEnabled( true );
        metaDataLabel.setEnabled( true );
    }

    /* Reduce button sizes if necessary so that their texts won't be cut off */
    private void initButtons() {

        /* Only reduce button sizes if the OS is Linux */
        if( System.getProperty( "os.name" ).equals( "Linux" ) ) {
            Font dialog10 = new Font( "Dialog", 1, 10 );
            addLabel.setFont( dialog10 );
            metaDataLabel.setFont( dialog10 );
            planLabel.setFont( dialog10 );
            saveConfigLabel.setFont( dialog10 );
            createCSVLabel.setFont( dialog10 );
            createSQLInsertLabel.setFont( dialog10 );
            createSQLMergeLabel.setFont( dialog10 );
        }
    }

    /* Initialize Help Messages */
    private void initHelp() {

        /* Help Panel displays this message when the cursor is on CSV Data Snapshot */
        csvSnapshotHelp = "CSV DATA SNAPSHOT\n\n" +
                "The snapshot of all data from the uploaded CSV file.";

        /* Help Panel displays this message when the cursor is on Add New Column button */
        addNewColHelp = "ADD NEW COLUMN\n\n" +
                "Adds a new column with data from Banner into the CSV Data Snapshot.";

        /* Help Panel displays this message when the cursor is on Column Field */
        columnHelp = "COLUMN TEXT FIELD\n\n" +
                "The CSV Data Snapshot column that is currently on focus.\n" +
                "You can edit the name of the column through this Text Field.";

        /* Help Panel displays this message when the cursor is on the Column List */
        sqlListHelp = "COLUMN LIST\n\n" +
                "Specifies a list of Database Columns, where the selected column content is going to be saved" +
                "\n\n" +
                "e.g.\n" +
                "SATURN > SPRIDEN > SPRIDEN_LAST_NAME\n" +
                "ALUMNI > APBCONS > APBCONS_PREF_LAST_NAME";

        /* Help Panel displays this message when the cursor is on the "Produce Data Type and Length" button */
        dataTypeLengthHelp = "DATA TYPE & LENGTH REPORT\n\n" +
                "Save the Data Types and Lengths of the CSV Data Snapshot columns into a file.";

        /* Help Panel displays this message when the cursor is on the "Report Plan" button */
        planHelp = "REPORT PLAN\n\n" +
                "Displays information that helps you understand the way CSV Loader executes your " +
                "configuration:\n\n" +
                "1. Plan Tab lists the Database columns where the data from CSV Data Snapshot are going to be " +
                "inserted/merged.\n\n" +
                "2. Data Comparison Tab compares the existing Database data side-by-side with the new data " +
                "coming from the CSV Data Snapshot.";

        /* Help Panel displays this message when the cursor is on the "Save Configuration to File" button */
        saveConfigHelp = "SAVE CONFIGURATION TO FILE\n\n" +
                "Save the column configurations from the 'Do not Load this Column' checkboxes and " +
                "Column Lists into a file.";

        /* Help Panel displays this message when the cursor is on the "Create CSV" button */
        createCSVHelp = "CREATE CSV\n\n" +
                "Save the data in CSV Data Snapshot into a CSV file.";

        /* Help Panel displays this message when the cursor is on the "Create SQL Insert" button */
        createInsertHelp = "CREATE SQL INSERT\n\n" +
                "Create SQL Insert Statements from the data in CSV Data Snapshot.";

        /* Help Panel dsplays this message when the cursor is on the "Create SQL Merge" button */
        createMergeHelp = "CREATE SQL MERGE\n\n" +
                "Create SQL Merge Statements from the data in CSV Data Snapshot.\n\n" +
                "IMPORTANT: Create SQL Merge button can only run if the Primary Keys of the tables, where " +
                "the statements are going to be executed, exist in the CSV Data Snapshot.";
    }

    private void initTable() {
        csvTable.getTableHeader().setReorderingAllowed( false );
        csvTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
    }

    private void loadCol( int colIndex ) {
        if( colIndex != -1 ) {

            String dataType = currentImage.dataTypeArrayList.get( colIndex );

            /* Load the fields with selected column values */

            try {
                columnTextField.setText( currentImage.columnArrayList.get( colIndex ) );
            }
            catch( NullPointerException ne ) { columnTextField.setText( null ); }

            try {
                dataTypeTextField.setText( dataType );
            }
            catch( NullPointerException ne ) { dataTypeTextField.setText( null ); }

            try {
                if( currentImage.nullArrayList.get( colIndex ) == true )
                    nullTextField.setText( "NULL" );
                else
                    nullTextField.setText( "NOT NULL" );
            }
            catch( NullPointerException ne ) { nullTextField.setText( "NULL" ); }

            try {
                if( dataType.indexOf( "INVALID" ) > -1 ){
                    dataTypeTextField.setForeground( main.red );
                    dataTypeTextField.setText( dataType );
                    includeCheckBox.setSelected( true );
                    includeCheckBox.setEnabled( false );
                }
                else {
                    dataTypeTextField.setForeground( main.black );
                    includeCheckBox.setEnabled( true );
                    includeCheckBox.setSelected( currentImage.includeArrayList.get( colIndex ) );
                }
            }
            catch( NullPointerException ne ) { includeCheckBox.setSelected( false ); }

            try {
                listArrayList = new ArrayList<String>( currentImage.sqlArrayList.get( colIndex ) );
                sqlList.setListData( listArrayList.toArray() );
            }
            catch( NullPointerException ne ) { sqlList.setListData( new ArrayList<String>().toArray() ); }

        }
    }

    public void reloadCSVTable() {
        csvTable.setModel( new StaticTableModel( main.get2DVector( currentImage.csvDataArrayList ), new Vector<String>( currentImage.columnArrayList ) ) );

        if( selectedColIndex == csvTable.getColumnCount() )
            selectedColIndex--;

        if( selectedColIndex > -1 ) {
            csvTable.setColumnSelectionInterval( selectedColIndex, selectedColIndex );
            csvTable.setRowSelectionInterval( selectedRowIndex, selectedRowIndex );
            loadCol( selectedColIndex );
        }
    }

    public void reloadCol() {
        loadCol( selectedColIndex );
    }

    /* Displays the ArrayList parameter into JTable, and save it into Backup Image and Current Image */
    public void setCSVData( ArrayList<ArrayList<String>> dataArrayList, ArrayList<String> titleArrayList ) {
        csvTable.setModel( new StaticTableModel( main.get2DVector( dataArrayList ), new Vector<String>( titleArrayList ) ) );

        enablePanel();

        currentImage = new CSVPanelImage( main, dataArrayList, titleArrayList );

        selectedColIndex = 0;
        selectedRowIndex = 0;

        csvTable.setColumnSelectionInterval( selectedColIndex, selectedRowIndex );
        csvTable.setRowSelectionInterval( selectedColIndex, selectedRowIndex );
        loadCol( selectedColIndex );
    }

    /* Set the SQL Columns, where to save the data */
    public void setSqlListData( ArrayList<String> listArrayList ) {
        this.listArrayList = new ArrayList<String>( listArrayList );
        sqlList.setListData( listArrayList.toArray() );
        updateCurrentImage( SQL );
    }

    /* Update the Current Image with a new value */
    private void updateCurrentImage( int field ) {
        try {
            if( selectedColIndex > -1 ) {
                if( field == COLUMN ) {
                    currentImage.columnArrayList.set( selectedColIndex, columnTextField.getText() );
                    reloadCSVTable();
                }
                else if( field == INCLUDE )
                    currentImage.includeArrayList.set( selectedColIndex, includeCheckBox.isSelected() );
                else
                    currentImage.sqlArrayList.set( selectedColIndex, new ArrayList<String>( listArrayList ) );
            }
        }
        catch( NullPointerException e ) {}
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel actionPanel;
    private javax.swing.JLabel addLabel;
    private javax.swing.JLabel addSqlLabel;
    private javax.swing.JLabel closeLabel;
    private javax.swing.JLabel colonLabel3;
    private javax.swing.JLabel colonLabel4;
    private javax.swing.JLabel colonLabel5;
    private javax.swing.JLabel columnLabel;
    private javax.swing.JPanel columnPanel;
    private javax.swing.JTextField columnTextField;
    private javax.swing.JLabel createCSVLabel;
    private javax.swing.JLabel createSQLInsertLabel;
    private javax.swing.JLabel createSQLMergeLabel;
    private javax.swing.JScrollPane csvScrollPane;
    public javax.swing.JTable csvTable;
    private javax.swing.JLabel dataTypeLabel;
    private javax.swing.JTextField dataTypeTextField;
    private javax.swing.JPanel helpPanel;
    private javax.swing.JScrollPane helpScrollPane;
    private javax.swing.JTextPane helpTextPane;
    private javax.swing.JCheckBox includeCheckBox;
    private javax.swing.JLabel metaDataLabel;
    private javax.swing.JLabel nullLabel;
    private javax.swing.JTextField nullTextField;
    private javax.swing.JLabel planLabel;
    private javax.swing.JLabel removeSqlLabel;
    private javax.swing.JLabel saveConfigLabel;
    private javax.swing.JPanel sqlActionPanel;
    private javax.swing.JList sqlList;
    private javax.swing.JPanel sqlPanel;
    private javax.swing.JScrollPane sqlScrollPane;
    // End of variables declaration//GEN-END:variables

    public CSVPanelImage currentImage;
    public int selectedColIndex;
    private int selectedRowIndex;
    private Main main;
    private String addNewColHelp;
    private String columnHelp;
    private String createCSVHelp;
    private String createInsertHelp;
    private String createMergeHelp;
    private String csvSnapshotHelp;
    private String dataTypeLengthHelp;
    private String planHelp;
    private String saveConfigHelp;
    private String sqlListHelp;
    public ArrayList<String> listArrayList;
    private static final int COLUMN = 0;
    private static final int INCLUDE = 1;
    private static final int SQL = 2;
}
